<?php

class Retailer_Backend_Block_Adminhtml_Account_Edit_Tab_Address extends Mage_Adminhtml_Block_Widget_Form
{
  protected function _prepareForm()
  {
      $form = new Varien_Data_Form();
      $this->setForm($form);
      $link = Mage::getModel('backend/backend')->load(Mage::getSingleton('admin/session')->getUser()->getUserId(),'user_id');
      $data = Mage::getModel('customer/customer')->load($link->getCustomerId())->getDefaultBillingAddress();
      $form->setDataObject($data);
      $fieldset = $form->addFieldset('backend_form', array('legend'=>Mage::helper('backend')->__('Account information')));
      if($link->getCustomerId()==0){
          $fieldset->addField('disabled', 'label', array(
              'label'     => Mage::helper('backend')->__('In order to set addresses, you must first assign a customer to be linked to Admin'), //Mage::getModel('admin/user')->load($session->getId())->getId()
              'class'     => 'required-entry',
              'required'  => false,
              'name'      => 'disabled',
          ));
          $fieldset->addField('spawn', 'checkbox', array(
              'label'     => Mage::helper('backend')->__('Create Linked Customer'), //Mage::getModel('admin/user')->load($session->getId())->getId()
              //'class'     => 'required-entry',
              //'required'  => false,
              'name'      => 'spawn',
              'value'     => 'check',
          ));
      }
      else{
         $fieldset->addField('company', 'text', array(
              'label'     => Mage::helper('backend')->__('Company:'), //Mage::getModel('admin/user')->load($session->getId())->getId()
              'class'     => 'required-entry',
              'required'  => false,
              'name'      => 'company',
          ));
          $fieldset->addField('street', 'text', array(
              'label'     => Mage::helper('backend')->__('Address:'), //Mage::getModel('admin/user')->load($session->getId())->getId()
              'class'     => 'required-entry',
              'required'  => false,
              'name'      => 'street',
          ));
          $fieldset->addField('city', 'text', array(
              'label'     => Mage::helper('backend')->__('City:'), //Mage::getModel('admin/user')->load($session->getId())->getId()
              'class'     => 'required-entry',
              'required'  => false,
              'name'      => 'city',
          ));
          $fieldset->addField('region', 'text', array(
              'label'     => Mage::helper('backend')->__('State:'), //Mage::getModel('admin/user')->load($session->getId())->getId()
              'class'     => 'required-entry',
              'required'  => false,
              'name'      => 'region',
          ));
          $fieldset->addField('postcode', 'text', array(
              'label'     => Mage::helper('backend')->__('ZIP Code:'), //Mage::getModel('admin/user')->load($session->getId())->getId()
              'class'     => 'required-entry',
              'required'  => false,
              'name'      => 'postcode',
          ));
          $fieldset->addField('country_id', 'hidden', array(
              'label'     => Mage::helper('backend')->__(''), //Mage::getModel('admin/user')->load($session->getId())->getId()
              //'class'     => 'required-entry',
              'required'  => false,
              'name'      => 'country_id',
          ));
          $fieldset->addField('telephone', 'text', array(
              'label'     => Mage::helper('backend')->__('Telephone Number:'), //Mage::getModel('admin/user')->load($session->getId())->getId()
              'class'     => 'required-entry',
              'required'  => false,
              'name'      => 'telephone',
          ));
          $fieldset->addField('fax', 'text', array(
              'label'     => Mage::helper('backend')->__('Fax Number:'), //Mage::getModel('admin/user')->load($session->getId())->getId()
              'class'     => 'required-entry',
              'required'  => false,
              'name'      => 'fax',
          ));
          $fieldset->addField('entity_id', 'hidden', array(
              'label'     => Mage::helper('backend')->__("Id"),
              'required'  => false,
              'name'      => 'entity_id',
          ));
      }
      
//
//     $fieldset->addField('password', 'text', array(
//          'label'     => Mage::helper('backend')->__('Password(security reasons)'),
//          'required'  => true,
//          'name'      => 'password',
//      ));
//
//      $fieldset->addField('status', 'select', array(
//          'label'     => Mage::helper('backend')->__('Status'),
//          'name'      => 'status',
//          'values'    => array(
//              array(
//                  'value'     => 1,
//                  'label'     => Mage::helper('backend')->__('Enabled'),
//              ),
//
//              array(
//                  'value'     => 2,
//                  'label'     => Mage::helper('backend')->__('Disabled'),
//              ),
//          ),
//      ));
//
//      $fieldset->addField('content', 'editor', array(
//          'name'      => 'content',
//          'label'     => Mage::helper('backend')->__('Content'),
//          'title'     => Mage::helper('backend')->__('Content'),
//          'style'     => 'width:700px; height:500px;',
//          'wysiwyg'   => false,
//          'required'  => false,
//      ));
                
     
      if ( Mage::getSingleton('adminhtml/session')->getBackendData() )
      {
          $form->setValues($data->getData());
          Mage::getSingleton('adminhtml/session')->setBackendData(null);
      } elseif ( $data ) {
          //$form->setValues(Mage::registry('backend_data'));
          $form->setValues($data->getData());
      }
      
      return parent::_prepareForm(); 
  }
}